package com.hzdesk.media.koreabatchmatvector.custom;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2018/8/1.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class myProgressBar extends View {

    private int widthSize;
    private int heightSize;
    private int PaintColor = 0xff1295db; //#123256
    private Paint mPaint;
    private int progressWith = 400;
    private int offset = 0;

    public myProgressBar(Context context) {
        this(context,null);
    }

    public myProgressBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public myProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(PaintColor);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        widthSize = MeasureSpec.getSize(widthMeasureSpec);
        heightSize = MeasureSpec.getSize(heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(offset+0,0,offset+progressWith,heightSize,mPaint);
    }
    public void refresh(){
    new Thread(myRunnable).start();
    }
   private Runnable myRunnable = new Runnable() {
       @Override
       public void run() {
          while (true){
              if(offset < widthSize){
                  try {
                      offset += 6;
                      postInvalidate();
                      Thread.sleep(5);
                  } catch (InterruptedException e) {}
              }else{
                  offset = 0;
              }
          }
       }
   };
}
